home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / object oriented files / CConfigDirector.cp < prev    next >
Encoding:
Text File  |  1993-11-17  |  6.2 KB  |  248 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CConfigDirector.c
  3.  
  4.         
  5.     SUPERCLASS = CDLOGDirector
  6.     
  7.     Copyright © 1991 Symantec Corporation. All rights reserved.
  8.     
  9.  
  10.  ******************************************************************************/
  11.  
  12. #include "CConfigDirector.h"
  13. #include <CScrollPane.h>
  14. #include <CDialogText.h>
  15. #include <CDialog.h>
  16. #include <CPaneBorder.h>
  17. #include <CApplication.h>
  18. #include <CTextEnvirons.h>
  19. #include <CButton.h>
  20. #include <CCheckBox.h>
  21. #include <CRadioControl.h>
  22. #include <CDialogText.h>
  23. #include <CPopupMenu.h>
  24. #include <CPopupPane.h>
  25. #include <CBartender.h>
  26.  
  27. extern CBartender    *gBartender;
  28.  
  29. char    gOptions[500];
  30. extern short        prefsRefNum;
  31.  
  32. static Boolean ByKind( CView *scrollPane, void* targetID)
  33.     {
  34.     return member(scrollPane, CScrollPane);
  35.     }
  36.  
  37. static Boolean ByKind_set_text( CView *pane, void* targetID)
  38.     {
  39.     if (member(pane, CDialogText))
  40.         {
  41.         short id = ((CDialogText *)pane)->GetID();
  42.         Handle    aResource = GetResource('PREF',id);
  43.         ((CDialogText *)pane)->SetTextHandle(aResource);
  44.         }
  45.     }
  46.  
  47. static Boolean ByKind_get_text( CView *pane, void* targetID)
  48.     {
  49.     if (member(pane, CDialogText))
  50.         {
  51.         short id = ((CDialogText *)pane)->GetID();
  52.         Handle    aResource = GetResource('PREF',id);
  53.         if (!aResource)
  54.             {
  55.             aResource = NewHandle(0);
  56.             AddResource(aResource,'PREF',id,"\p");
  57.             }
  58.         else
  59.             {
  60.             SetHandleSize(aResource, 0);
  61.             }
  62.         HandAndHand(((CDialogText *)pane)->GetTextHandle(), aResource);
  63.         ChangedResource(aResource);
  64.         WriteResource(aResource);
  65.         }
  66.     }
  67.  
  68. static Boolean ByCommand( CView *item, void* targetID)
  69.     {
  70.     long    command = (long)targetID;
  71.     
  72.     if (member(item, CButton) && (command == ((CButton *)item)->GetClickCmd()))
  73.         {
  74.         return ((CButton *)item)->GetValue() || !member(item, CRadioControl);
  75.         }
  76.     else if (member(item, CPopupPane))
  77.         {
  78.         CPopupMenu *aMenu = ((CPopupPane *)item)->GetMenu();
  79.         short        selectedItem, mID;
  80.         MenuHandle    mHandle;
  81.     
  82.         gBartender->FindMenuItem( command, &mID, &mHandle, &selectedItem);
  83.  
  84.         return (selectedItem != 0);
  85.         }
  86.     else
  87.         return false;
  88.     }
  89.  
  90. void CConfigDirector::IConfigDirector( short Aboutid, CDirectorOwner *aSupervisor)
  91.     {
  92.     long theCommand;
  93.     CScrollPane *scrollPane;
  94.     Handle Data = GetResource( 'TEXT', Aboutid);
  95.     Str255    name;
  96.     ResType    rType;
  97.     FailNILRes(Data);
  98.     GetResInfo(Data,&Aboutid,&rType,name);
  99.  
  100.     CDLOGDirector::IDLOGDirector( Aboutid, aSupervisor);
  101.     
  102.     itsData = Data;    
  103.     itsWindow->SetTitle(name);
  104.     scrollPane = (CScrollPane *)itsWindow->MatchView( ByKind, 0);
  105.  
  106.     if (scrollPane)
  107.         {
  108.         StScrpHandle styleHandle = (StScrpHandle) GetResource( 'styl', Aboutid);
  109.         CPaneBorder *listBorder;
  110.         Rect    margin;
  111.         Cell    aCell;    
  112.  
  113.         itsMainPane = new(CStyleText);
  114.         itsGopher = itsMainPane;
  115.  
  116.         itsMainPane->IStyleText(scrollPane, this,
  117.                     1, 1, 0, 0, sizELASTIC, sizELASTIC, 1000);
  118.         itsMainPane->Specify( kNotEditable, kNotSelectable, kNotStylable);
  119.         itsMainPane->FitToEnclosure(TRUE, TRUE);
  120.         itsMainPane->Offset( 2, 2, FALSE);
  121.         SetRect(&margin, 0, 0, -2, -2);
  122.         itsMainPane->ChangeSize( &margin, FALSE);
  123.         
  124.         if (Data) itsMainPane->SetTextHandle(Data);
  125.  
  126.         // Install the styles
  127.         
  128.         if (styleHandle) itsMainPane->SetStyleScrap( 0, MAXINT, styleHandle, TRUE);
  129.         
  130.         scrollPane->InstallPanorama(itsMainPane);
  131.         }
  132.  
  133.     UseResFile(prefsRefNum);        
  134.     itsWindow->MatchView( ByKind_set_text, 0);
  135.     
  136.     for ( theCommand = 20000 ; theCommand < 21000; theCommand += 2)
  137.         {            
  138.         int deflt = gOptions[(theCommand-20000)>>1];
  139.         /* set check box / radio button state */
  140.         
  141.         if (deflt < 2)
  142.             {
  143.             CButton *hit = (CButton *)itsWindow->MatchView( ByCommand, (void *)theCommand);
  144.             if (hit && member(hit, CCheckBox))
  145.                 {
  146.                 ((CCheckBox *)hit)->SetValue(deflt);
  147.                 }
  148.             else if (hit && member(hit, CPopupPane))
  149.                 {
  150.                 CPopupMenu *aMenu = ((CPopupPane *)hit)->GetMenu();
  151.                 short        selectedItem, mID;
  152.                 MenuHandle    mHandle;
  153.             
  154.                 gBartender->FindMenuItem( theCommand, &mID, &mHandle, &selectedItem);
  155.                 
  156.                 aMenu->SelectItem(selectedItem, deflt?pmForceOn:pmForceOff);
  157.                 }
  158.             }
  159.         else
  160.             {
  161.             CRadioControl *hit = (CRadioControl *)itsWindow->FindViewByID(deflt);
  162.             if (hit && member(hit, CRadioControl))
  163.                     hit->SetValue(BUTTON_ON);
  164.             }
  165.         }
  166.     }    /* CConfigDirector::IConfigDirector */
  167.  
  168. void CConfigDirector::Dispose( void)
  169.     {
  170.     UseResFile(prefsRefNum);
  171.     if (!ResError())
  172.         {
  173.         Handle    aResource = GetResource('PREF',20000);
  174.         if (!aResource)
  175.             {
  176.             aResource = NewHandle(0);
  177.             AddResource(aResource,'PREF',20000,"\pgcc switches");
  178.             }
  179.         else
  180.             {
  181.             SetHandleSize(aResource, 0);
  182.             }
  183.         PtrAndHand(&gOptions, aResource, sizeof (gOptions));
  184.         ChangedResource(aResource);
  185.         WriteResource(aResource);
  186.         itsWindow->MatchView( ByKind_get_text, 0);
  187.         }
  188.     itsMainPane = 0;
  189.     inherited::Dispose();
  190.     }
  191.  
  192. void    CConfigDirector::DoCommand( long theCommand)
  193.     {
  194.     Handle    Data = NULL;
  195.     StScrpHandle styleHandle = NULL;
  196.     CButton *hit = NULL;
  197.     
  198.     if (( theCommand >= 20000 ) && ( theCommand < 21000))    /* check boxes / radio buttons */
  199.         {            
  200.         /* save check box / radio button state */
  201.         int idx = (theCommand-20000)>>1;
  202.         hit = (CButton *)itsWindow->MatchView( ByCommand, (void *)theCommand);
  203.         if (hit && member(hit, CCheckBox))
  204.             {
  205.             gOptions[idx] = ((CCheckBox *)hit)->IsChecked();
  206.             }
  207.         else if (hit && member(hit, CRadioControl))
  208.             {
  209.             gOptions[idx] = ((CCheckBox *)hit)->GetID();
  210.             }
  211.         else if (hit && member(hit, CPopupPane))
  212.             {
  213.             CPopupMenu *aMenu = ((CPopupPane *)hit)->GetMenu();
  214.             short        selectedItem, mID;
  215.             MenuHandle    mHandle;
  216.         
  217.             gBartender->FindMenuItem( theCommand, &mID, &mHandle, &selectedItem);
  218.             
  219.             gOptions[idx] = !(aMenu->ItemIsChecked(selectedItem));
  220.             }
  221.         else gOptions[idx] = 0;
  222.         theCommand += gOptions[idx];
  223.         }
  224.     else
  225.         {
  226.             inherited::DoCommand( theCommand);
  227.             return;
  228.         }
  229.         
  230.     Data = GetResource('TEXT', (short)theCommand);
  231.     styleHandle = (StScrpHandle) GetResource( 'styl', (short)theCommand);
  232.     itsData = Data;
  233.     if (Data)             
  234.             {
  235.             itsMainPane->SetTextHandle(Data);
  236.             if (styleHandle) itsMainPane->SetStyleScrap( 0, MAXINT, styleHandle, TRUE);
  237.             }
  238.     else
  239.             {
  240.             Str255  wTitle;     
  241.             Str255  wNumber;    
  242.             CopyPString((StringPtr)"\pNo help for this option\rIf necessary, add as TEXT resource ", wTitle);
  243.             NumToString((short)theCommand, wNumber);
  244.             ConcatPStrings(wTitle, wNumber);
  245.             itsMainPane->SetTextPtr((char *)&wTitle[1], *wTitle);
  246.             }
  247.     }
  248.